package com.lxg.dao;


import com.lxg.pojo.Books;
import com.lxg.pojo.Borrow;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface BorrowDao {

    /**
     * 查询书架全部的书本
     * @return
     */
    @Select("select * from borrow where is_deleted = 0 and uid = #{uid}")
    public ArrayList<Borrow> getAllMyBooks(Integer uid);

    /**
     * 添加图书进书架
     * @return
     */

    @Insert("insert into borrow (bid,uid,bookname,author,num,status) " +
            "values (#{bid},#{uid},#{bookname},#{author},#{num},#{status})")
    public boolean addMyBook(Integer bid,Integer uid,String bookname,String author,Integer num,Integer status);

    @Select("select * from borrow where is_deleted = 0 and bid = #{bid} and uid = #{uid}")
    Borrow getBorrow(Integer bid,Integer uid);


    @Update("update borrow set num=#{num} where bid=#{bid} and uid = #{uid}")
    boolean updateBorrow(Integer bid,Integer uid,Integer num);

    @Update("update  borrow set is_deleted = 1 where bid=#{bid} and uid = #{uid}")
    boolean deleteBorrow(Integer bid,Integer uid);

    @Select("select is_deleted from borrow where bid = #{bid} and uid = #{uid}")
    Integer isDeleted(Integer uid,Integer bid);


    @Update("update  borrow set status = 1 where bid=#{bid} and uid = #{uid}")
    boolean updateBorrowStatus(Integer bid, Integer uid);
}
